#include "CameraBehaviour.h"

#include "PlayerBehaviour.h"

CameraBehaviour::CameraBehaviour(Camera* camera, GameObject* toFollow) : Behaviour(camera), toFollow(toFollow) {

}

CameraBehaviour::~CameraBehaviour() {

}

void CameraBehaviour::update(float step) {
    glm::mat4 transform = toFollow->getTransform();
    glm::vec3 z = glm::vec3(transform[2][0], transform[2][1], transform[2][2]);

    glm::vec3 pos = toFollow->getLocation() - (z * 10.0f); // Put the camera a distance from player
    glm::vec3 up = glm::vec3(transform[1][0], transform[1][1], transform[1][2]);

    parent->setTransform(glm::inverse(glm::lookAt(pos, toFollow->getLocation(), up))); // Put the camera behind the player
}
